package com.spic.business.accident.feedback.controller;

import com.spic.business.accident.feedback.domain.AccidentExperenceBack;
import com.spic.business.accident.feedback.service.IAccidentExperenceBackService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 经验反馈单Controller
 *
 * @author spic
 * @date 2021-12-20
 */
@RestController
@RequestMapping("accident/feedback")
public class AccidentExperenceBackController extends BaseController {
    @Autowired
    private IAccidentExperenceBackService accidentExperenceBackService;

    /**
     * 查询经验反馈单列表
     */
    @PreAuthorize(hasPermi = "business/accident:feedback:list")
    @GetMapping("/list")
    public TableDataInfo list(AccidentExperenceBack accidentExperenceBack) {
        startPage();
        List<AccidentExperenceBack> list = accidentExperenceBackService.selectAccidentExperenceBackList(accidentExperenceBack);
        return getDataTable(list);
    }

    /**
     * 导出经验反馈单列表
     */
    @PreAuthorize(hasPermi = "business/accident:feedback:export")
    @Log(title = "经验反馈单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccidentExperenceBack accidentExperenceBack) throws IOException {
        List<AccidentExperenceBack> list = accidentExperenceBackService.selectAccidentExperenceBackList(accidentExperenceBack);
        ExcelUtil<AccidentExperenceBack> util = new ExcelUtil<AccidentExperenceBack>(AccidentExperenceBack.class);
        util.exportExcel(response, list, "经验反馈单数据");
    }

    /**
     * 获取经验反馈单详细信息
     */
    @PreAuthorize(hasPermi = "business/accident:feedback:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(accidentExperenceBackService.selectAccidentExperenceBackById(id));
    }

    /**
     * 新增经验反馈单
     */
    @PreAuthorize(hasPermi = "business/accident:feedback:add")
    @Log(title = "经验反馈单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccidentExperenceBack accidentExperenceBack) {
        return toAjax(accidentExperenceBackService.insertAccidentExperenceBack(accidentExperenceBack));
    }

    /**
     * 修改经验反馈单
     */
    @PreAuthorize(hasPermi = "business/accident:feedback:edit")
    @Log(title = "经验反馈单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccidentExperenceBack accidentExperenceBack) {
        return toAjax(accidentExperenceBackService.updateAccidentExperenceBack(accidentExperenceBack));
    }

    /**
     * 删除经验反馈单
     */
    @PreAuthorize(hasPermi = "business/accident:feedback:remove")
    @Log(title = "经验反馈单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(accidentExperenceBackService.deleteAccidentExperenceBackByIds(ids));
    }
}
